package com.lihuacats.bilibili.task.bilibili_task.controller.job;

import com.lihuacats.bilibili.task.bilibili_task.task.BiliStart;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Random;

/**
 * @author : kurisu
 * @className : SignJob
 * @description : 签到任务
 * @date: 2021-10-19 15:19
 */
@Component
@Slf4j
public class SignJob {

    private final BiliStart biliStart;

    @Autowired
    public SignJob(final BiliStart biliStart) {
        this.biliStart = biliStart;
    }

    @Scheduled(cron = "0 30 9 ? * 1-5")
    public void week() {
        try {
            Thread.sleep(new Random().nextInt(30) * 1000 * 60);
            biliStart.start();
        } catch (InterruptedException e) {
            log.error("【week】等待过程中出错", e);
        }
    }


    @Scheduled(cron = "0 0 11 ? * 6,7")
    public void weekend() {
        try {
            Thread.sleep(new Random().nextInt(45) * 1000 * 60);
            biliStart.start();
        } catch (InterruptedException e) {
            log.error("【weekend】等待过程中出错", e);
        }
    }
}
